using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using Mr.LinqToWeibo.SearchCriteria;

namespace Mr.LinqToWeibo
{
	public class WeiboApi
	{
		private IDictionary<string, Func<ISearchCriteria, string>> paramMap =
            new Dictionary<string, Func<ISearchCriteria, string>> ();
		private Func<ISearchCriteria, string> apiFunc;

		public WeiboApi (Func<ISearchCriteria, string> apiFunc, params KeyValuePair<string, Func<ISearchCriteria, string>>[] keyValues)
		{
			if (apiFunc == null) {
				throw new ArgumentNullException ("apiFunc");
			}

			this.apiFunc = apiFunc;

			if (keyValues != null) {
				foreach (var keyValue in keyValues) {
					this.paramMap.Add (keyValue);
				}
			}
		}

		public string GetApi(ISearchCriteria criteria) { 
			if(criteria != null)
			{
				return this.apiFunc(criteria);
			}
			return string.Empty;
		}
		
		public IDictionary<string, Func<ISearchCriteria, string>> ParamMappings {
			get {
				return this.paramMap;
			}
		}
	}
}

